package test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import movement.Location;

import org.junit.Before;
import org.junit.Test;

import unit.*;

import dispatch.DispatchCenter;

import emergency.*;

public class testRequirements {
	Emergency em;
	DispatchCenter center;
	Garage garage;
	
	
	private RequirementsEmergency startOfRequirementsChain;
	RequirementsLocalFire localFireRequirements = new RequirementsLocalFire();
	RequirementsHouseFire houseFireRequirements = new RequirementsHouseFire();
	RequirementsFacilityFire facilityFireRequirements = new RequirementsFacilityFire();
	RequirementsTrafficAccident trafficAccidentRequirements = new RequirementsTrafficAccident();
	RequirementsRobbery robberyRequirements = new RequirementsRobbery();
	RequirementsPublicDisturbance publicDisturbanceRequirements = new RequirementsPublicDisturbance();
	RequirementDefaultEmergency defaultEmergencyRequirement = new RequirementDefaultEmergency();
	
    public void setRequirements(){		
		localFireRequirements.setNextInChain(houseFireRequirements);
		houseFireRequirements.setNextInChain(facilityFireRequirements);
		facilityFireRequirements.setNextInChain(trafficAccidentRequirements);
		trafficAccidentRequirements.setNextInChain(publicDisturbanceRequirements);
		publicDisturbanceRequirements.setNextInChain(robberyRequirements);
		robberyRequirements.setNextInChain(defaultEmergencyRequirement);
		
		startOfRequirementsChain = localFireRequirements;
	}
    
    @Before
    public void setUp() throws Exception { 
    	setRequirements();
    	center = new DispatchCenter("DC", new Location(20,20,"Loc"), new Location(30,30,"Garage"));
    	garage = center.getGarage();
    	em = new Fire(new Location(10,10,"Loc"),Severity.BENIGN,center,Fire.Size.FACILITY,false,2,2);
    }
	
    @Test
    public void testChain(){
    	assertEquals(startOfRequirementsChain, localFireRequirements);
    	assertEquals(localFireRequirements.getNextInChain(),houseFireRequirements);
    	assertEquals(houseFireRequirements.getNextInChain(), facilityFireRequirements);
    	assertEquals(facilityFireRequirements.getNextInChain(),trafficAccidentRequirements);
    	assertEquals(trafficAccidentRequirements.getNextInChain(), publicDisturbanceRequirements);
    	assertEquals(publicDisturbanceRequirements.getNextInChain(),robberyRequirements);
    	assertEquals(robberyRequirements.getNextInChain(),defaultEmergencyRequirement);
    }
	
	@Test
    public void testGetUnitsNeededAndGetAvailableUnits(){
    	ArrayList<Unit> units = new ArrayList<Unit>();
    	units.add(new PoliceCar("Jan", 20, garage));
    	units.add(new PoliceCar("Jef", 20, garage));
    	units.add(new PoliceCar("Jos", 20, garage));
    	units.add(new Ambulance("Jut", 20, garage));
    	units.add(new Ambulance("Jat", 20, garage));
    	units.add(new Ambulance("Jet", 20, garage));
    	units.add(new Ambulance("Jot", 20, garage));
    	units.add(new FireTruck("Jut2", 20, garage, Fire.Size.FACILITY));
    	units.add(new FireTruck("Jat2", 20, garage, Fire.Size.FACILITY));
    	units.add(new FireTruck("Jet2", 20, garage, Fire.Size.FACILITY));
    	units.add(new FireTruck("Jet3", 20, garage, Fire.Size.FACILITY));
  
    	assertEquals(11,em.createSuggestion(units).size());
    	assertEquals(11,em.getTotalUnitsNeeded()); // em requires 11 units 
    }
}
